"""
-------------------------------
- File_Name: student.py
- Date: 2025/2/14
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 学生相关pydantic模型
-------------------------------
"""
from app.core.security import get_password_hash, verify_password
from pydantic import BaseModel, Field, field_validator, model_validator


class StudentBase(BaseModel):
    sno: int
    name: str
    pwd: str
    note: str | None = None

class StudentIn(StudentBase):
    @field_validator("pwd")
    @classmethod
    def validate_pwd(cls, v):
        return get_password_hash(v)

class StudentUpdate(BaseModel):
    sno: int | None = None
    name: str | None = None
    pwd: str | None = None
    note: str | None = None

    @field_validator("pwd")
    @classmethod
    def validate_pwd(cls, v):
        return get_password_hash(v)

class StudentDB(StudentBase):
    pwd: str

class StudentOut(StudentBase):
    id: int
    name: str = Field(serialization_alias="username")  # 在序列化使用别名
    pwd: str = Field(serialization_alias="password", exclude=True) # 序列化是排除字段